<template>
	<view class="box">
		<!-- 导航 -->
		<uv-navbar title="新增地址" bgColor="#f7f6fa" height="44px" titleStyle="{font-weight: bold;font-size: 1.1rem;}"
			@click="goback"></uv-navbar>
		<view class="list" v-for="item in UserList" :key="item.id">
			<view class="all">
				<view class="all-left">
					<image src="../../static/image/位置.png" mode=""></image>
				</view>
				<view class="all-right">
					<view class="all-top">
						<view class="all-top1">{{item.name}}
							<view style="font-size:0.8rem;color: #bdbdbd;">{{item.mobile}}</view>
						</view>
					</view>
					<view class="all-bottom">{{item.address}}</view>
				</view>
			</view>
			<view class="group">
				<uv-radio-group v-model="radiovalue">
					<uv-radio :name="item.id" activeColor="#008c8c"></uv-radio>
					<view @click="changeAddress(item.id)">默认地址</view>
				</uv-radio-group>
				<view class="group1">
					<uv-icon @click="DeleteInformation(item.id)" name="trash" size="22px"></uv-icon>
					<uv-icon @click="ModifyQuery(item.id)" name="search" size="22px"></uv-icon>
					<uv-icon @click="changeAddress(item.id)" name="edit-pen" size="22px"></uv-icon>
				</view>
			</view>

		</view>
		<!-- 按钮 -->
		<view class="btn">
			<uv-button @click="goNewaddress" type="primary" color="#008c8c" shape="circle" text="新增地址"></uv-button>
		</view>
		<!-- 弹出层 -->
		<uv-popup ref="popup" bgColor="none" :closeable="true">
			<view class="tanchu" style="width: 600rpx;background-color: #fff; padding: 20rpx;border-radius: 20rpx;">
				宠物修改信息显示
				<uv-cell-group>
						<uv-cell title="用户名" :value="list.name" :center="true"></uv-cell>
						<uv-cell title="手机号" :value="list.mobile" :center="true"></uv-cell>
						<uv-cell title="地区" :value="list.area" :center="true"></uv-cell>
						<uv-cell title="地址" :value="list.address" :center="true"></uv-cell>
					</uv-cell-group>

			<!-- 	<uv-button v-for="item in UserList" :key="item.id" @click="AddressModification(item.id)" type="primary"
					color="#008c8c" shape="circle" text="修改地址"></uv-button> -->
			</view>
		</uv-popup>
	</view>
</template>

<script>
	import {
		myRequest
	} from '@/request/request.js'
	export default {
		data() {
			return {
				// 指定列表id
				UserId: '',
				// 用户列表
				UserList: '',
				// 查询数据
				list: '',
				// 用户名
				name: '',
				// 手机号
				phone: '',
				// 地区
				area: '',
				// 地址
				address: '',
				// 单选框
				radiovalue: '苹果'
			}
		},
		created() {

			// 用户地址查询
			const that = this
			myRequest('address/index?server=1', function(err, data) {
				if (err) {
					console.log(err);
				} else {
					that.UserList = data.data

					console.log("成功", that.UserList);
				}
			}, 'GET', {

			})
		},
		methods: {
		// 去修改地址`
		changeAddress(e){
			console.log(e);
			uni.navigateTo({
				url: `/pages/newaddress/newaddress?e=${JSON.stringify(e)}`
			})
		},
			// 查询信息
			ModifyQuery(e) {
				const name = e
				// console.log(name);
				const that = this
				myRequest('address/edit?server=1', function(err, data) {
					if (err) {
						uni.showToast({
							title: err,
						});
					} else {
						that.list = data.data
						// console.log("成功", that.list);
					}
				}, 'POST', {
					id: name
				})
				this.$refs.popup.open();
			},
			// 删除
			DeleteInformation(e) {
				const name = e
				console.log(name);
				myRequest('address/delete?server=1', function(err, data) {
					if (err) {
						uni.showToast({

							title: err,
						});
					} else {

						console.log("成功");
					}
				}, 'GET', {
					id: name
				})
			},
			goNewaddress() {

				uni.navigateTo({
					url: '/pages/newaddress/newaddress'
				})
			},
			goback() {
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style lang="scss">
	@import url("deliveryaddress.scss");
</style>